2.8.3 Generators
- Collection generators can be used to generate a tuple, a set or a matrix.
- Series generators use the familiar summation and product notation; they place an addition or multiplication operation between the expressions in a sequence to produce a series.
- Generalized series generators place an arbitrary binary operator between the expressions in a sequence. They use the syntactic form of collection generators and the semantics of series generators.
Generators can be expanded symbolically using Distribute or evaluated using Evaluate . When distributed, an expanded value can be produced if the domains are manifest. When evaluated, an expanded value can be produced if the templates and domains can be bound.
The descriptions provided here address the syntax of generators. For more information on collections, see §6.2. For more information on how to work with generators, see §6.3.
2.8.3.1 Series Generators
Syntactically, series generators use a form similar to definite integration: an introductory symbol followed by a three-element list of expressions, a concluding ⅆ and an index variable. The first two expressions provide lower and upper bounds for the generator. The third expression provides an element template for terms in the series. The introductory symbols are ∑ for summation and ∏ for product. Figure 2.42 displays the standard form of series-generator syntax along with some variations.

(a) Series

(b) Bounds
Generator | Input | Alternate | Display |
Summation | ∑0,n,i^2 ⅆi | ∑i=0,n,i^2 | ![]() |
Product | ∏2,n+1,i^2 ⅆi | ∏i=2,n+1,i^2 | ![]() |
The examples in the Alternate column of Figure 2.43 more closely resemble mathematical notation. When the alternate syntax is used, the trailing ⅆ and variable are no longer needed (and are not allowed). While this is closer to the usual mathematical notation for generators, a generator of this form must be parenthesized if it participates in a larger expression. In contrast, parenthesization is not required for the standard form of generator because it is delimited naturally by ⅆ.
A second syntactic variation provides control over the increment
value. When a value other than the default increment of 1 is needed,
another expression can be inserted just before the template
expression. For example, the input
∑-1,1,.5,x^2$dx
displays as
2.8.3.2 Generalized Series Generators
Syntactically, a generalized series generator looks like a tuple
generator with a binary operator in place of the template.
The
summation
When used with the ± operator, a generalized series generates an
2.8.3.3 Collection Values and Generators
Tuple, set and matrix values use comma-separated lists
of expressions to denote elements of collections.
However, when there is a relationship between elements,
the list can be condensed using a generator.
These generators use a syntax taken from
linear-algebra and set-theory notation. Like series generators,
collection generators require a

(a) Tuple value and generator

(b) Domains

(c) Interval domains
The path in Figure 2.44 (a) that traverses at least one domain denotes a tuple generator.
To illustrate, a simple tuple generator is entered as
(x|x∈1,3)
and displayed as
Syntactic Form | Display Form | |
R1 | (x|x∈1,3) | ![]() |
R2 | (x|x∈(1,4)co) | ![]() |
R3 | (x|x∈1,3,.5) | ![]() |
R4 | (x|x∈3,1,-1) | ![]() |
P1 | (x|1≤x≤3) | ![]() |
P2 | (x|(1≤x)∧(x<4)) | ![]() |
C1 | (x|x∈(1,2,3)) | ![]() |
C2 | (x|x∈cʈ) | ![]() |
A1 | (x^2|x∈𝕏) | ![]() |
A2 | ((√y,y)ʋ|y∈𝕐) | ![]() |
Figure 2.45 contains examples showing the use of different domain expressions in a tuple generator.
Most of the examples generate the same tuple. Example R2 makes use of interval notation. R3 uses a non-integer step value
and R4 uses a negative step value. The predicate
examples P1 and P2 infer a control variable from the predicate expression. The first of these has a more efficient implementation
than the second and may be preferred for that reason. Example C1 creates a tuple of scalars from the elements of another tuple, but the
source could be any collection. In example C2, the source is another tuple; in this example the generator
is not manifest and therefore cannot be distributed, but with a definition of
Predicates used in tuple generators can be almost any expression that contains one variable and evaluates to a Boolean result.
The implementation tests a range of values bounded by constants inferred from the predicate.
However, there are some limits to the use of predicates. A generator with a predicate like
The syntax diagram in Figure 2.44 shows that a tuple generator can have more than one domain. The domains
are composed by nesting trailing domains within leading domains. For example,


The second form of matrix generator uses just one domain expression which references another matrix. The
simplest form of this,
The third form of matrix generator also uses just one domain expression (which cannot be a matrix domain)
and a tuple in the template. The domain generates the rows and the template describes what should be in each row.
For example,